package com.atwulidun.mediator17;

public abstract class Colleague {
    // 维护一个Mediator子类对象
    protected Mediator mediator;
    // 对Colleague子类对象的描述
    protected String des;

    public Colleague(Mediator mediator, String des) {
        this.mediator = mediator;
        this.des = des;
    }

    // 发送消息的抽象方法
    protected abstract void sendMsg(String msg);

    // 接收消息的抽象方法
    protected abstract void receiveMsg(String msg);
}

// Colleague的具体子类
// 中国类
class ChinaColleague extends Colleague {
    public ChinaColleague(Mediator mediator, String des) {
        super(mediator, des);
        // 把当前对象放进mediator所维护的Map中
        mediator.nations.put(des, this);
    }

    @Override
    protected void sendMsg(String msg) {
        mediator.communicate(des,msg);
    }

    @Override
    protected void receiveMsg(String msg) {
        System.out.println("中国接收到的消息为：" + msg);
    }
}
// 日本类
class JapanColleague extends Colleague {
    public JapanColleague(Mediator mediator, String des) {
        super(mediator, des);
        // 把当前对象放进mediator所维护的Map中
        mediator.nations.put(des, this);
    }

    @Override
    protected void sendMsg(String msg) {
        mediator.communicate(des,msg);
    }

    @Override
    protected void receiveMsg(String msg) {
        System.out.println("日本接收到的消息为：" + msg);
    }
}
class KoreaColleague extends Colleague {
    public KoreaColleague(Mediator mediator, String des) {
        super(mediator, des);
        // 把当前对象放进mediator所维护的Map中
        mediator.nations.put(des, this);
    }

    @Override
    protected void sendMsg(String msg) {
        mediator.communicate(des, msg);
    }

    @Override
    protected void receiveMsg(String msg) {
        System.out.println("韩国接收到的消息为：" + msg);
    }
}